<?php //pack11class

class TypeManager {
    
    public static $typesDone=false;
    public static $typesByID=array();
    public static $typesByName=array();

    public static function getType($id=false) {

        if(!self::$typesDone) self::getTypes();
        if(!$id) return self::$typesByName;

        if(is_numeric($id)) {
            if(array_key_exists($id, self::$typesByID)){
                return self::$typesByID[$id];
            } else {
                return false;
            }
        } else {
            if(array_key_exists($id, self::$typesByName)){
                return self::$typesByName[$id];
            } else {
                return false;
            }
        }
    }

    private static function getTypes() {
        $types=MySQLGet::process("Select * from ".MySQL::TABLE_TYPES." where `active` is not null order by ".LanguagesManager::ssql().";");
        if(!$types) return false;
        foreach($types as $row) {
            $type=new Type();
            $type->id=$row["id"];
            $type->label=$row[LanguagesManager::field()];
            $type->system=$row["system"];
            self::$typesByID[$type->id]=$type;
            self::$typesByName[$type->system]=$type;
        }
        self::$typesDone=true;
    }

}
?>
